﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;

namespace ETWebApi2
{
    public class WriteBug
    {
        /// <summary>
        /// 写日志文件
        /// </summary> 
        /// <param name="msg"></param>
        /// <param name="loginid">当前登陆者工号</param>
        public void WriteBugLog(string currentFun, string msg)
        {
            try
            {
                string filename = HttpContext.Current.Server.MapPath("/file") + "\\error.log";
                if (File.Exists(filename))
                {
                    using (FileStream fs = new FileStream(filename, FileMode.Append, FileAccess.Write))
                    {
                        using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
                        {
                            sw.Write("【" + DateTime.Now + "】【" + currentFun + "】\r\r\r\r  " + msg + "\r\n");
                        }
                    }
                }
                else
                {
                    using (FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write))
                    {
                        using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
                        {
                            sw.Write("【" + DateTime.Now + "】【" + currentFun + "】\r\r\r\r  " + msg + "\r\n");
                        }
                    }
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}